#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>

int glob = 6;
char buf[] = "a write to stdout\n";

int main() {
	int var;
	pid_t pid;

	var = 88;
	if (write(STDOUT_FILENO, buf, sizeof(buf)-1) != sizeof(buf)-1) {
		printf("write error: %s\n", strerror(errno));
		return -1;
	}
	printf("before fork\n");

	if ((pid=fork()) < 0) {
		printf("fork error: %s\n", strerror(errno));
		return -1;
	}
	else if (pid == 0) {
		glob++;
		var++;
	}
	else {
		sleep(2);
	}

	printf("pid = %d, ppid = %d, uid = %d, gid = %d, euid = %d, egid = %d\n", \
		getpid(), getppid(), getuid(), getgid(), geteuid(), getegid());
	printf("var = %d, glob = %d\n", var, glob);
	return 0;
}